package model;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.Box;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

public class GameFrame extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2601588613080786213L;
	
	private static final int DEFAULT_WIDTH = 1024;
	private static final int DEFAULT_HEIGHT = 768;
	
	Board board = new Board();
	
	public Board getBoard() {
		return board;
	}

	public void init() {
		add(board);
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setTitle("Susan - Board Game");
		
		setVisible(true);
		
		setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
		
		createMenu();
	}
	
	public void createMenu() {
		JMenuBar menu = new JMenuBar();
		JMenu fileMenu = new JMenu("File");
			
		JMenuItem newGame = new JMenuItem("New Game");
		Actions newGameAction = new Actions("newGameAction");
		newGame.addActionListener(newGameAction);
		
		JMenuItem quit = new JMenuItem("Quit Game");
		Actions quitGameAction = new Actions("quitGameAction");
		quit.addActionListener(quitGameAction);
		
		fileMenu.add(newGame);
		fileMenu.add(quit);
		fileMenu.setMnemonic(KeyEvent.VK_F);
		
		menu.add(fileMenu);
		menu.add(Box.createHorizontalGlue());
		this.setJMenuBar(menu);
	}
	
	private class Actions implements ActionListener{
		private String s1;
		
		public Actions(String s) {
			s1 = s;
		}
		
		public void actionPerformed(ActionEvent event) {
			if (s1 == "quitGameAction") {
				System.exit(0);
			}
			else if (s1 == "newGameAction") {
				board = new Board();
				State.initState();
			}
		}
	}
}
